Skip to content

## What's broken MaskedLinearOperator.to(device=...) crashes with AttributeError when called with a device but no dtype (e.g. .to(device="cpu")). The base LinearOperator.to() handles device-only moves fine; this subclass override (added to keep bool masks from being cast to float) regresses that path.#133

Open
devteamaegis wants to merge 1 commit into
cornellius-gp:mainfrom
devteamaegis:fix/masked-to-device-no-dtype

Conversation

@devteamaegis

Copy link
Copy Markdown

Why it happens

_to_helper returns dtype=None when only a device is supplied, but the override evaluates arg.dtype.is_floating_point == dtype.is_floating_point unconditionally, so dtype.is_floating_point raises when dtype is None.

Fix

Guard with dtype is not None: when no dtype is requested, move every arg (including masks) by device only, preserving the bool dtype — matching base to().

Test

Added test_to_device (device-only move keeps masks boolean). Fails before (AttributeError), passes after; full masked-operator suite (167) green.

_to_helper returns dtype=None when only a device is passed. The
MaskedLinearOperator.to override then accessed dtype.is_floating_point
unconditionally, raising AttributeError. Guard for dtype is None so a
device-only move keeps masks boolean, matching the base to() behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant